package com.study.util;

import redis.clients.jedis.Jedis;

public class RedisMasterSlave {

	public static void main(String[] args) throws InterruptedException {
		Jedis master = new Jedis("192.168.150.129",6379);//主机  
		master.auth("1234");
        Jedis slave = new Jedis("192.168.150.129",6579);//从机  
        slave.auth("1234");
        //设置6579服务器的主机为6379
        slave.slaveof("192.168.150.129",6379);  
      
        master.select(1);
        master.setex("a",100,"100");//主机去写  
          
        //延迟一秒，防止内存中读写太快，读在写之前先完成而出现null的情况  
        Thread.sleep(1000);  
        
        slave.select(1);
        String result = slave.get("a");//从机去读  
        System.out.println(result);  
        
        master.close();
        slave.close();
	}
}
